package com.wx.service.impl;

import com.wx.dao.SmbmsUserDao;
import com.wx.entry.SmbmsUser;
import com.wx.service.LoginService;
import com.wx.utils.MybatisUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class LoginServiceImpl implements LoginService {

    @Override
    public boolean login(String userCode, String userPassword) {
        System.out.println(userCode);
        System.out.println(userPassword);
        //service  业务层，职责，调用dao层，获得数据库中返回的数据，进行业务逻辑的处理和判断。
//        SmbmsUserDaoImpl smbmsUserDao = new SmbmsUserDaoImpl();
//        SmbmsUser smbmsUser =  smbmsUserDao.getSmbmsUserByUserCode(userCode);
        SqlSession sqlSession =  MybatisUtils.getSqlSession();
        SmbmsUserDao smbmsUserDao=   sqlSession.getMapper(SmbmsUserDao.class);
      SmbmsUser  smbmsUser =   smbmsUserDao.getSmbmsUserByUserCode(userCode);
        MybatisUtils.closeSqlSession(sqlSession);
        if(smbmsUser!=null){
            if(userPassword.equals(smbmsUser.getUserPassword())){
                return true;
            }else {
                return  false;
            }
        }else {
            return false;
        }
    }
}
